
USE `open_scriptures`;

BEGIN;
SET FOREIGN_KEY_CHECKS = 0;

DELETE FROM `language`;
DELETE FROM `text`;

-- English
INSERT INTO language (`code`, `name`) VALUES('en', 0);
INSERT INTO text (`language`, `data`) VALUES('en', "English");
SET @textID = LAST_INSERT_ID();
UPDATE language SET `name` = @textID WHERE code = 'en' AND `name` = 0;

-- Spanish
INSERT INTO language (`code`, `name`) VALUES('es', 0);
INSERT INTO text (`language`, `data`) VALUES('en', "Spanish");
SET @textID = LAST_INSERT_ID();
UPDATE language SET `name` = @textID WHERE code = 'es' AND `name` = 0;
INSERT INTO text (`id`, `language`, `data`) VALUES (@textID, 'es', "Español");


-- Latin
INSERT INTO language (`code`, `name`) VALUES('la', 0);
INSERT INTO text (`language`, `data`) VALUES('en', "Latin");
SET @textID = LAST_INSERT_ID();
UPDATE language SET `name` = @textID WHERE code = 'la' AND `name` = 0;

-- Hebrew
INSERT INTO language (`code`, `name`, direction) VALUES('hbo', 0, 'rtl');
INSERT INTO text (`language`, `data`) VALUES('en', "Hebrew");
SET @hboTextID = LAST_INSERT_ID();
UPDATE language SET `name` = @hboTextID WHERE code = 'hbo' AND `name` = 0;

-- Greek
INSERT INTO language (`code`, `name`) VALUES('grc', 0);
INSERT INTO text (`language`, `data`) VALUES('en', "Greek");
SET @grcTextID = LAST_INSERT_ID();
UPDATE language SET `name` = @grcTextID WHERE code = 'grc' AND `name` = 0;

-- Aramaic
INSERT INTO language (`code`, `name`, direction) VALUES('oar', 0, 'rtl');
INSERT INTO text (`language`, `data`) VALUES('en', "Aramaic");
SET @oarTextID = LAST_INSERT_ID();
UPDATE language SET `name` = @oarTextID WHERE code = 'oar' AND `name` = 0;

-- Arabic
INSERT INTO language (`code`, `name`, direction) VALUES('ar', 0, 'rtl');
INSERT INTO text (`language`, `data`) VALUES('en', "Arabic");
SET @arTextID = LAST_INSERT_ID();
UPDATE language SET `name` = @arTextID WHERE code = 'ar' AND `name` = 0;

--
-- -- Spanish
-- INSERT INTO language (`code`, `name`) VALUES('es', 0);
-- SET @esLanguageID = LAST_INSERT_ID();
-- INSERT INTO text (`language`, `data`) VALUES(@esLanguageID, "Español");
-- SET @esTextID = LAST_INSERT_ID();
-- UPDATE language SET `name` = @esTextID WHERE id = @esLanguageID;
-- 
-- INSERT INTO text (text_id, `code`, `data`) VALUES (@textID, @esLanguageID, "Inglés");
-- INSERT INTO text (text_id, `code`, `data`) VALUES (@esTextID, @enLanguageID, "Spanish");


SET FOREIGN_KEY_CHECKS = 1;
COMMIT;